package com.esiag.sgbd;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.logging.Logger;


public class Test {

	public static void main(String[] args) {
		Connection conn = null;
		PreparedStatement prestat = null;
		ResultSet pw = null;
		try {
			
			Class.forName("org.apache.derby.jdbc.ClientDriver").newInstance();
		} catch (InstantiationException e) {
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		}
		
		Calendar calendar1 = new GregorianCalendar();
		int heure1 = calendar1.get(java.util.Calendar.HOUR_OF_DAY);
		int minute1 = calendar1.get(java.util.Calendar.MINUTE);
		int seconde1 = calendar1.get(java.util.Calendar.SECOND);
		
		try {
			int i = 10000;
			//long n = 9876543210L;
		while(i>0)
			{	
			conn = DriverManager.getConnection("jdbc:derby://localhost:1527/MyDbTest;");
		
			prestat = conn.prepareStatement("SELECT * FROM testTable");
			pw = prestat.executeQuery();
			while(pw.next())
			{
				System.out.println(i);
				System.out.println(pw.getInt(1)+", "+pw.getString(2));
			}
	
			i=i-1;
			}
			
			Calendar calendar2 = new GregorianCalendar();
			int heure2 = calendar2.get(java.util.Calendar.HOUR_OF_DAY);
			int minute2 = calendar2.get(java.util.Calendar.MINUTE);
			int seconde2 = calendar2.get(java.util.Calendar.SECOND);
		
			System.out.println("heure : " + heure1 + " minute : "+ minute1+ " seconde : "+ seconde1);
			
			System.out.println("heure : " + heure2 + " minute : "+ minute2+ " seconde : "+ seconde2);
			
			pw.close();
			pw = null;
			prestat.close();
			conn.close();
			conn = null;
		
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		//Logger logger = Logger.getLogger("com.esiag.sgbd.Test");
	
	}

}
